package com.yourenbang.lingyun.transaction.constant;

import com.yourenbang.lingyun.constants.BizCodeMessages;
import com.yourenbang.lingyun.constants.enums.fund.AccountMainJournalType;
import com.yourenbang.lingyun.constants.enums.fund.AccountType;
import com.yourenbang.lingyun.core.exception.BizRuntimeException;
import com.yourenbang.lingyun.transaction.web.domain.vo.JournalInfoVO;

public class ChangeTypeConstant {


    /**
     * V2版本 银小云 合并提现后使用
     *
     * @param toAccountType          账户类型  {@link AccountType}
     * @param accountMainJournalType 资金流水主类型 {@link AccountMainJournalType}
     * @return 资金明细类型
     */
    public static JournalInfoVO getAddJournalTypeV2(AccountType toAccountType, AccountMainJournalType accountMainJournalType) {

        if (AccountType.ALLY_V2.isEquals(toAccountType)) {

            if (AccountMainJournalType.ALLY_REFUND.isEquals(accountMainJournalType)) {
                return new JournalInfoVO(
                        AccountType.SYS_V2_OUT,
                        toAccountType,
                        accountMainJournalType
                );

            } else {
                return new JournalInfoVO(
                        AccountType.SYS_V2_OUT,
                        toAccountType,
                        accountMainJournalType
                );
            }

        }

        if (AccountType.ALLY_FROM_BOSS.isEquals(toAccountType)) {

            if (AccountMainJournalType.ALLY_REFUND.isEquals(accountMainJournalType)) {

                return new JournalInfoVO(
                        AccountType.SYS_BOSS_OUT,
                        toAccountType,
                        accountMainJournalType
                );

            } else {

                return new JournalInfoVO(
                        AccountType.SYS_BOSS_OUT,
                        toAccountType,
                        accountMainJournalType
                );
            }
        }

        if (AccountType.MERCHANT_FROM_BOSS.isEquals(toAccountType)) {

            return new JournalInfoVO(
                    AccountType.SYS_BOSS_OUT,
                    toAccountType,
                    accountMainJournalType
            );

        }

        if (AccountType.MER.isEquals(toAccountType)) {

            return new JournalInfoVO(
                    AccountType.SYS_V2_OUT,
                    toAccountType,
                    accountMainJournalType
            );

        }

        throw new BizRuntimeException(BizCodeMessages.VALIDATOR_ERR);

    }

    /**
     * 获取减帐流水信息,即:往toAccountType进行accountMainJournalType减帐操作,流水类型、资金账户对应关系信息
     *
     * @param toAccountType          账户类型
     * @param accountMainJournalType 资金主类型
     * @return
     */
    public static JournalInfoVO getSubtractJournalTypeV2(AccountType toAccountType, AccountMainJournalType accountMainJournalType) {


        if (AccountType.ALLY_V2.isEquals(toAccountType)) {
            //平台资金账户
            if (AccountMainJournalType.ALLY_V2_OUT.isEquals(accountMainJournalType)) {
                //盟友减帐
                return new JournalInfoVO(
                        AccountType.SYS_V2_WITHDRAW,
                        toAccountType,
                        AccountMainJournalType.ALLY_V2_OUT
                );
            }

        }

        //从庄家资金账号减帐
        if (AccountType.ALLY_FROM_BOSS.isEquals(toAccountType)) {

            if (AccountMainJournalType.ALLY_V2_OUT.isEquals(accountMainJournalType)) {
                //盟友减帐
                return new JournalInfoVO(
                        AccountType.SYS_BOSS_WITHDRAW,
                        toAccountType,
                        AccountMainJournalType.ALLY_V2_OUT
                );
            }

        }

        if (AccountType.SYS_V2_WITHDRAW.isEquals(toAccountType)) {
            //平台资金账户
            if (AccountMainJournalType.ALLY_V2_OUT.isEquals(accountMainJournalType)) {
                //盟友减帐
                return new JournalInfoVO(
                        AccountType.ALLY_V2,
                        toAccountType,
                        AccountMainJournalType.ALLY_V2_OUT
                );
            }

        }

        //从庄家资金账号减帐
        if (AccountType.SYS_BOSS_WITHDRAW.isEquals(toAccountType)) {

            if (AccountMainJournalType.ALLY_V2_OUT.isEquals(accountMainJournalType)) {
                //盟友减帐
                return new JournalInfoVO(
                        AccountType.ALLY_FROM_BOSS,
                        toAccountType,
                        AccountMainJournalType.ALLY_V2_OUT
                );
            }

        }

        throw new BizRuntimeException(BizCodeMessages.VALIDATOR_ERR);

    }

    /**
     * 获取加帐冲正流水信息(流水类型、资金发起方、资金接收方对应关系)
     * <p>
     * 即:往fromAccountType进行accountMainJournalType冲正操作时,流水类型、资金发起方、资金接收方对应关系
     *
     * @param fromAccountType        资金发起方
     * @param accountMainJournalType 资金主类型
     * @return
     */
    public static JournalInfoVO getReversalJournalType(AccountType fromAccountType, AccountMainJournalType accountMainJournalType) {


        // 盟友平台钱包冲正,资金返回平台加帐账户
        if (AccountType.ALLY_V2.isEquals(fromAccountType)) {
            if (AccountMainJournalType.ALLY_REFUND.isEquals(accountMainJournalType)) {
                //盟友冲正
                return new JournalInfoVO(
                        fromAccountType,
                        AccountType.SYS_V2_OUT,
                        accountMainJournalType
                );
            }

        }

        // 盟友boss钱包冲正,资金返回boss加帐账户
        if (AccountType.ALLY_FROM_BOSS.isEquals(fromAccountType)) {
            if (AccountMainJournalType.ALLY_REFUND.isEquals(accountMainJournalType)) {
                return new JournalInfoVO(
                        fromAccountType,
                        AccountType.SYS_BOSS_OUT,
                        accountMainJournalType
                );
            }

        }

        // 平台商户钱包冲正,资金返回平台加帐账户
        if (AccountType.MER.isEquals(fromAccountType)) {
            if (AccountMainJournalType.MERCHANT_REFUND.isEquals(accountMainJournalType)) {
                return new JournalInfoVO(
                        fromAccountType,
                        AccountType.SYS_V2_OUT,
                        accountMainJournalType
                );
            }

        }

        // boss商户钱包冲正,资金返回boss加帐账户
        if (AccountType.MERCHANT_FROM_BOSS.isEquals(fromAccountType)) {
            if (AccountMainJournalType.MERCHANT_REFUND.isEquals(accountMainJournalType)) {
                return new JournalInfoVO(
                        fromAccountType,
                        AccountType.SYS_BOSS_OUT,
                        accountMainJournalType
                );
            }
        }

        throw new BizRuntimeException(BizCodeMessages.VALIDATOR_ERR);

    }

    /**
     * 获取冻结资金流水类型
     *
     * @param toAccountType
     * @param accountMainJournalType
     * @return
     */
    public static JournalInfoVO getDepositJournalTypeV2(AccountType toAccountType, AccountMainJournalType accountMainJournalType) {


        if (AccountType.ALLY_V2.isEquals(toAccountType)) {
            //平台资金账户
            if (AccountMainJournalType.ALLY_V2_OUT.isEquals(accountMainJournalType)) {
                //盟友减帐
                return new JournalInfoVO(
                        AccountType.SYS_V2_WITHDRAW,
                        toAccountType,
                        accountMainJournalType
                );
            }

        }

        //从庄家资金账号减帐
        if (AccountType.ALLY_FROM_BOSS.isEquals(toAccountType)) {

            if (AccountMainJournalType.ALLY_V2_OUT.isEquals(accountMainJournalType)) {
                //盟友减帐
                return new JournalInfoVO(
                        AccountType.SYS_BOSS_WITHDRAW,
                        toAccountType,
                        accountMainJournalType
                );
            }
        }

        //从庄家资金账号减帐(商户提现)
        if (AccountType.MERCHANT_FROM_BOSS.isEquals(toAccountType)) {

            if (AccountMainJournalType.MERCHANT_OUT.isEquals(accountMainJournalType)) {
                //盟友减帐
                return new JournalInfoVO(
                        AccountType.SYS_BOSS_WITHDRAW,
                        toAccountType,
                        accountMainJournalType
                );
            }
        }

        //盟友平台钱包余额支付
        if (AccountType.SYS_V2_WITHDRAW.isEquals(toAccountType)) {

            if (AccountMainJournalType.BALANCE_PAY.isEquals(accountMainJournalType)) {
                //盟友减帐
                return new JournalInfoVO(
                        AccountType.ALLY_V2,
                        toAccountType,
                        accountMainJournalType
                );
            }
        }

        //盟友BOSS钱包余额支付
        if (AccountType.SYS_BOSS_WITHDRAW.isEquals(toAccountType)) {

            if (AccountMainJournalType.BALANCE_PAY.isEquals(accountMainJournalType)) {
                //盟友减帐
                return new JournalInfoVO(
                        AccountType.ALLY_FROM_BOSS,
                        toAccountType,
                        accountMainJournalType
                );
            }
        }

        throw new BizRuntimeException(BizCodeMessages.VALIDATOR_ERR);

    }

}
